
package py.una.pol.raphapy.autoventas.model;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Rafael E. Benegas
 */
@Entity
@Table(name = "persona")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Persona.findAll", query = "SELECT p FROM Persona p"),
    @NamedQuery(name = "Persona.findByCodPer", query = "SELECT p FROM Persona p WHERE p.codPer = :codPer"),
    @NamedQuery(name = "Persona.findByNomPer", query = "SELECT p FROM Persona p WHERE p.nomPer = :nomPer"),
    @NamedQuery(name = "Persona.findByApePer", query = "SELECT p FROM Persona p WHERE p.apePer = :apePer"),
    @NamedQuery(name = "Persona.findByFecNac", query = "SELECT p FROM Persona p WHERE p.fecNac = :fecNac")})
public class Persona implements Serializable {
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "persona")
    private Collection<Direccion> direccionCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "persona")
    private Collection<Telefono> telefonoCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "persona")
    private Collection<DocumentoPersona> documentoPersonaCollection;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "persona")
    private Vendedor vendedor;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "persona")
    private Cliente cliente;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "cod_per")
    private Long codPer;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "nom_per")
    private String nomPer;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "ape_per")
    private String apePer;
    @Basic(optional = false)
    @NotNull
    @Column(name = "fec_nac")
    @Temporal(TemporalType.DATE)
    private Date fecNac;
    @JoinColumn(name = "cod_tip_per", referencedColumnName = "cod_tip_per")
    @ManyToOne(optional = false)
    private TipoPersona codTipPer;

    public Persona() {
    }

    public Persona(Long codPer) {
        this.codPer = codPer;
    }

    public Persona(Long codPer, String nomPer, String apePer, Date fecNac) {
        this.codPer = codPer;
        this.nomPer = nomPer;
        this.apePer = apePer;
        this.fecNac = fecNac;
    }

    public Long getCodPer() {
        return codPer;
    }

    public void setCodPer(Long codPer) {
        this.codPer = codPer;
    }

    public String getNomPer() {
        return nomPer;
    }

    public void setNomPer(String nomPer) {
        this.nomPer = nomPer;
    }

    public String getApePer() {
        return apePer;
    }

    public void setApePer(String apePer) {
        this.apePer = apePer;
    }

    public Date getFecNac() {
        return fecNac;
    }

    public void setFecNac(Date fecNac) {
        this.fecNac = fecNac;
    }

    public TipoPersona getCodTipPer() {
        return codTipPer;
    }

    public void setCodTipPer(TipoPersona codTipPer) {
        this.codTipPer = codTipPer;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (codPer != null ? codPer.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        
        if (!(object instanceof Persona)) {
            return false;
        }
        Persona other = (Persona) object;
        if ((this.codPer == null && other.codPer != null) || (this.codPer != null && !this.codPer.equals(other.codPer))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "py.una.pol.raphapy.autoventas.model.Persona[ codPer=" + codPer + " ]";
    }

    public Cliente getCliente() {
        return cliente;
    }

    public void setCliente(Cliente cliente) {
        this.cliente = cliente;
    }

    public Vendedor getVendedor() {
        return vendedor;
    }

    public void setVendedor(Vendedor vendedor) {
        this.vendedor = vendedor;
    }

    @XmlTransient
    public Collection<Direccion> getDireccionCollection() {
        return direccionCollection;
    }

    public void setDireccionCollection(Collection<Direccion> direccionCollection) {
        this.direccionCollection = direccionCollection;
    }

    @XmlTransient
    public Collection<Telefono> getTelefonoCollection() {
        return telefonoCollection;
    }

    public void setTelefonoCollection(Collection<Telefono> telefonoCollection) {
        this.telefonoCollection = telefonoCollection;
    }

    @XmlTransient
    public Collection<DocumentoPersona> getDocumentoPersonaCollection() {
        return documentoPersonaCollection;
    }

    public void setDocumentoPersonaCollection(Collection<DocumentoPersona> documentoPersonaCollection) {
        this.documentoPersonaCollection = documentoPersonaCollection;
    }
    
}
